package com.test.pattern.observer.before;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: SubscriptionSubject
 * @description: 具体主题类
 * @author: Mr du
 * @create: 2024-03-14 22:40
 */
public class SubscriptionSubject implements Subject{

    //定义一个集合用来存储多个观察者对象
    private List<Observer> weiXinUserList =new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weiXinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weiXinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weiXinUserList) {
            observer.update(message);
        }
    }
}
